<!--renshuai-->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="" prop="pdrName">
        <el-input
            v-model="queryParams.workerName"
            placeholder="师傅姓名"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="" prop="status">
        <el-select v-model="queryParams.status" placeholder="提现状态" clearable>
          <el-option  v-for="(item,index) in statusList" :key="item.value" :label="item.label" :value="item.value"/>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" width="50px" align="center">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="师傅姓名" align="center" prop="workerName" :show-overflow-tooltip="true"/>
      <el-table-column label="证件号" align="center" prop="idCardNo" :show-overflow-tooltip="true"/>
      <el-table-column label="手机号" align="center" prop="mobileNo" :show-overflow-tooltip="true"/>
      <el-table-column label="提现金额" align="center" prop="amount"/>
      <el-table-column label="支付方式" align="center" prop="payWay">
        <template slot-scope="scope">
          <dict-tag :options="payWayList" :value="scope.row.payWay"/>
        </template>
      </el-table-column>
      <el-table-column label="提现状态" align="center" prop="workStatus" width="90">
        <template slot-scope="scope">
          <dict-tag :options="statusList" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="申请时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyTime) }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope" v-if="scope.row.status!='2'">
          <el-button
              type="text"
              size="small"
              @click="handleAudit(scope.row)"
              v-hasPermi="['fin:worker:withd:audit']">审核</el-button>
          <el-button
              type="text"
              size="small"
              @click="handleSynWorker(scope.row)"
              v-hasPermi="['fin:worker:withd:synworker']">同步师傅信息</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改话框 -->
    <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body center :before-close="handleClose">
      <el-form ref="form" :model="form" :rules="rules" label-width="100px" v-loading="submitLoading">
        <el-row>
          <el-col :span="24">
            <el-form-item label="师傅姓名" prop="workName">
              <span>{{form.workerName}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="提现金额" prop="amount">
              <span>{{form.amount}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="支付方式" prop="amount">
              <span v-for="(item,index) in payWayList" :key="index" v-if="item.value==form.payWay">
                {{item.label}}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="form.payWay=='ALIPAY'">
            <el-form-item label="支付宝账号" prop="amount">
              <span>{{form.alipayAcct}}</span>
            </el-form-item>
          </el-col>

        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="onAuditPass">审核通过</el-button>
        <el-button @click="handleClose">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listWorkerWithdRecord, auditPass, synWorkerInfo} from "@/api/fin/workerWithd";

export default {
  name: "WorkerOrderSettlemList",
  data() {
    return {
      statusList:[
        {
          raw:{
            listClass:"warning",
            cssClass:""
          },
          value:"1",
          label:"待审核"
        },
        {
          raw:{
            listClass:"warning",
            cssClass:""
          },
          value:"2",
          label:"提现成功"
        },
        {
          raw:{
            listClass:"primary",
            cssClass:""
          },
          value:"9",
          label:"拒绝提现"
        }
      ],
      payWayList:[
        {
          raw:{
            listClass:"warning",
            cssClass:""
          },
          value:"WECHAT",
          label:"微信"
        },
        {
          raw:{
            listClass:"primary",
            cssClass:""
          },
          value:"ALIPAY",
          label:"支付宝"
        }
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      submitLoading: false,
      // 查询参数
      queryParams: {
        workerName: undefined,
        status:"1",
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {

      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      listWorkerWithdRecord(this.queryParams).then(response => {
        this.dataList = response.data;
        this.total = Number(response.total);
        this.loading = false;
      });
    },

    // 表单重置
    reset() {
      this.form = {
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.noticeId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },


    handleAudit(row){
      this.form=row;
      this.open = true;
      this.title = "审核";
    },
    handleSynWorker(row){
      synWorkerInfo(row.pkId,row.workerId).then(response => {
        this.$modal.msgSuccess("师傅信息同步完成");
        let data=response.data;
        row.workerName=data.realName;
        row.alipayAcct=data.alipayAcct;
        row.mobileNo = data.mobileNo;
        row.idCardNo=data.idCardNo;
      });
    },

    // 取消按钮
    handleClose() {
      this.open = false;
      this.reset();
    },

    onAuditPass(){
      this.submitLoading=true
      auditPass(this.form.pkId).then(response => {
        this.$modal.msgSuccess("支付成功");
        this.open = false;
        this.getList();
      }).finally(()=>{
        this.submitLoading=false;
      });
    },

  }
};
</script>
<style lang="scss" scoped>
</style>